<?php
include_once '../../lib/config.php';
include_once '../../lib/db.php';
include_once '../../lib/utils/tag.php';
include_once '../../model/rewarddanpunishment.php';

$proc = $_REQUEST['proc'];

switch ($proc){
	case "rnp-table":
		$key = $_POST['key'];
		$orderby = $_POST['orderby'];
		include '../../view/admin/rewarddanpunishment/tableList.php';
		break;
		
	case "add-modal":
		include '../../view/admin/rewarddanpunishment/rnp_add.php';
		break;
		
	case "rnp-add":
		$id = $_POST['rnp_id'];
		$nama = $_POST['rnp_nama'];
		$jenis = $_POST['rnp_jenis'];
		
		if ($id === '' || is_null($id)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi ID Reward/Punishment")); return ;
		}
		if ($nama === '' || is_null($nama)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Nama")); return ;
		}
		if ($jenis=== '' || is_null($jenis)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Jenis")); return ;
		}
		
		$ex = rnp_add($id, $nama, $jenis);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
		break;
		
	case "edit-modal":
		$rnp_id = $_POST['rnp_id'];
		include '../../view/admin/rewarddanpunishment/rnp_edit.php';
		break;
		
	case "rnp-edit":
		$id = $_POST['rnp_id'];
		$nama = $_POST['rnp_nama'];
		$jenis = $_POST['rnp_jenis'];
		
		if ($id === '' || is_null($id)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi ID Reward/Punishment")); return ;
		}
		if ($nama === '' || is_null($nama)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Nama")); return ;
		}
		if ($jenis=== '' || is_null($jenis)){
			echo json_encode(array('error'=> true, 'msg'=> "Mohon mengisi Jenis")); return ;
		}
		$ex = rnp_update($id, $nama, $jenis);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
		break;
	case "rnp-delete":
		$rnp_id = $_POST['rnp_id'];
		$ex = rnp_delete($rnp_id);
		echo json_encode(array('error'=> !$ex, 'msg'=> mysql_innodb_error(mysql_errno())));
}